package Tests;



import interfaz.ManagerArticuloIf;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;

import dto.ArticuloDTO;



public class ClienteBean {
	
	public static void main(String args[]) throws Exception{
        final String appName = "TPOAI_EAR";
        final String moduleName = "TPOAI";
        String sessionBeanName;
        String viewClassName;
		 Properties jndiProps = new Properties();
		 jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
		 jndiProps.put(Context.PROVIDER_URL,"remote://127.0.0.1:4447");
		 // username
		 jndiProps.put(Context.SECURITY_PRINCIPAL, "test1");
		 // password
		 jndiProps.put(Context.SECURITY_CREDENTIALS, "test123");
		 // This is an important property to set if you want to do EJB invocations via the remote-naming project
		 jndiProps.put("jboss.naming.client.ejb.context", true);
		 // create a context passing these properties
		 Context context = new InitialContext(jndiProps);
		 // lookup the bean     Foo
		 
	   
		//TEST PERSISTENCIA
		/* 
		//ARTICULO
		sessionBeanName = "ManagerArticulo";
	    viewClassName = ManagerArticuloIf.class.getName();
		ManagerArticuloIf admin =(ManagerArticuloIf)context.lookup(appName+"/"+moduleName+"/"+sessionBeanName+"!"+viewClassName);
		Articulo p =new Articulo();
	    p.setCodigo("12");
	    p.setDescripcion("Malla");
	    p.setDeposito("1234");
	    admin.save(p);
	    
	    //USER
	    sessionBeanName = "ManagerUser";
	    viewClassName = ManagerUserIf.class.getName();
	    ManagerUserIf admin1 =(ManagerUserIf)context.lookup(appName+"/"+moduleName+"/"+sessionBeanName+"!"+viewClassName);
	    User u=new User();
	    u.setEstado(EstadoType.ACTIVO);
	    u.setPassword("1");
	    u.setUsername("sa");
	    admin1.save(u);
	    
	    
	    
	    sessionBeanName = "ManagerOD";
	    viewClassName = ManagerODIf.class.getName();
	    ManagerODIf admin2 =(ManagerODIf)context.lookup(appName+"/"+moduleName+"/"+sessionBeanName+"!"+viewClassName);
	    OrdenDespacho od=new OrdenDespacho();
	    od.setEstado(1);
	    od.setFecha(new Date());
	    od.setNumeroDespacho(1);
	    od.setNumeroVenta(12);
	    od.setModulo(12);
	    
	    admin2.save(od);
	    
	    sessionBeanName = "ManagerSA";
	    viewClassName = ManagerSAIf.class.getName();
	    ManagerSAIf admin3 =(ManagerSAIf)context.lookup(appName+"/"+moduleName+"/"+sessionBeanName+"!"+viewClassName);
	    SolicitudArticulo sa=new SolicitudArticulo();
	    sa.setArticulo(p);
	    sa.setCantidad(23);
	    sa.setModulo(23);
	    admin3.save(sa);
	    */
		//USER
		//ARTICULO
			sessionBeanName = "ManagerArticulo";
		    viewClassName = ManagerArticuloIf.class.getName();
			ManagerArticuloIf admin =(ManagerArticuloIf)context.lookup(appName+"/"+moduleName+"/"+sessionBeanName+"!"+viewClassName);
			ArticuloDTO p =new ArticuloDTO();
		    p.setCodigo("12");
		    p.setDescripcion("Malla");
		    p.setDeposito("1234");
		    admin.save(p);
	    
	}
	
}
